package com.goodving.guli.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdateUnit;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.model.Keeper;

import cn.com.smartdevices.bracelet.config.Config;
import de.greenrobot.event.EventBus;

/**
 * Created by john on 2015/12/25.
 */
public class PersonInfoSettingUnitActivity extends SystemBarTintActivity implements View.OnClickListener {
    private PersonInfo f9120a;
    private View f9121b;
    private View f9122c;
    private View f9123d;
    private View f9124e;
    private View f9125f;
    private View f9126g;
    private View f9127h;
    private View f9128i;
    private View f9129j;
    private View f9130k;
    private View f9131l;
    private TextView f9132m;
    private TextView f9133n;
    private TextView f9134o;
    private TextView f9135p;
    private TextView f9136q;
    private TextView f9137r;
    private Config f9138s;
    private final String f9139t;

    public PersonInfoSettingUnitActivity() {
        this.f9139t = "PersonInfoSettingUnitActivity";
    }

    private void m13976a() {
        this.f9120a = Keeper.readPersonInfo();
        this.f9138s = Config.m8876h();
        m13978b();
        m13980c();
    }

    private void m13977a(int i) {
        if (i == R.id.person_info_length_unit_metric_area) {
            this.f9127h.setVisibility(View.VISIBLE);
            this.f9128i.setVisibility(View.INVISIBLE);
            this.f9133n.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9132m.setTextColor(getResources().getColor(R.color.highlight));
        } else if (i == R.id.person_info_length_unit_british_area) {
            this.f9127h.setVisibility(View.INVISIBLE);
            this.f9128i.setVisibility(View.VISIBLE);
            this.f9132m.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9133n.setTextColor(getResources().getColor(R.color.highlight));
        }
    }

    private void m13978b() {
        this.f9121b = findViewById(R.id.person_info_length_unit_metric_area);
        this.f9121b.setOnClickListener(this);
        this.f9122c = findViewById(R.id.person_info_length_unit_british_area);
        this.f9122c.setOnClickListener(this);
        this.f9124e = findViewById(R.id.person_info_weight_unit_british_area);
        this.f9124e.setOnClickListener(this);
        this.f9123d = findViewById(R.id.person_info_weight_unit_metric_area);
        this.f9123d.setOnClickListener(this);
        this.f9125f = findViewById(R.id.person_info_weight_unit_shijin_area);
        this.f9125f.setOnClickListener(this);
        this.f9126g = findViewById(R.id.person_info_weight_unit_text_hint_area);
        this.f9126g.setClickable(false);
        this.f9127h = findViewById(R.id.length_unit_metric);
        this.f9128i = findViewById(R.id.length_unit_british);
        this.f9129j = findViewById(R.id.weight_unit_metric);
        this.f9130k = findViewById(R.id.weight_unit_british);
        this.f9131l = findViewById(R.id.weight_unit_shijin);
        this.f9132m = (TextView) findViewById(R.id.length_unit_metric_txt);
        this.f9133n = (TextView) findViewById(R.id.length_unit_british_txt);
        this.f9134o = (TextView) findViewById(R.id.weight_unit_metric_txt);
        this.f9135p = (TextView) findViewById(R.id.weight_unit_british_txt);
        this.f9136q = (TextView) findViewById(R.id.weight_unit_shijin_txt);
        this.f9137r = (TextView) findViewById(R.id.weight_unit_text_hint);
    }

    private void m13979b(int i) {
        if (i == R.id.person_info_weight_unit_british_area) {
            this.f9130k.setVisibility(View.VISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.highlight));
            this.f9129j.setVisibility(View.INVISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9131l.setVisibility(View.INVISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.main_ui_title_color));
        } else if (i == R.id.person_info_weight_unit_metric_area) {
            this.f9130k.setVisibility(View.INVISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9129j.setVisibility(View.VISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.highlight));
            this.f9131l.setVisibility(View.INVISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.main_ui_title_color));
        } else if (i == R.id.person_info_weight_unit_shijin_area) {
            this.f9130k.setVisibility(View.INVISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9129j.setVisibility(View.INVISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.main_ui_title_color));
            this.f9131l.setVisibility(View.VISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.highlight));
        }
    }

    private void m13980c() {
        if (!this.f9138s.f4202l.f4259a.booleanValue()) {
            findViewById(R.id.person_info_weight_unit_shijin_and_txt_area).setVisibility(View.INVISIBLE);
        }
        m13977a(m13982d());
        if (DeviceSource.hasBindWeight()) {
            this.f9137r.setVisibility(View.VISIBLE);
            m13981c(m13983e());
            return;
        }
        this.f9137r.setVisibility(View.INVISIBLE);
        m13979b(m13983e());
    }

    private void m13981c(int i) {
        m13984f();
        if (i == R.id.person_info_weight_unit_british_area) {
            this.f9130k.setVisibility(View.VISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.highlight));
            this.f9129j.setVisibility(View.INVISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.text_color_gray));
            this.f9131l.setVisibility(View.INVISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.text_color_gray));
        } else if (i == R.id.person_info_weight_unit_metric_area) {
            this.f9130k.setVisibility(View.INVISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.text_color_gray));
            this.f9129j.setVisibility(View.VISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.highlight));
            this.f9131l.setVisibility(View.INVISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.text_color_gray));
        } else if (i == R.id.person_info_weight_unit_shijin_area) {
            this.f9130k.setVisibility(View.INVISIBLE);
            this.f9135p.setTextColor(getResources().getColor(R.color.text_color_gray));
            this.f9129j.setVisibility(View.INVISIBLE);
            this.f9134o.setTextColor(getResources().getColor(R.color.text_color_gray));
            this.f9131l.setVisibility(View.VISIBLE);
            this.f9136q.setTextColor(getResources().getColor(R.color.highlight));
        }
    }

    private int m13982d() {
        int i = this.f9120a.miliConfig.unit;
        return i == 1 ? R.id.person_info_length_unit_british_area : i == 0 ? R.id.person_info_length_unit_metric_area : R.id.person_info_length_unit_metric_area;
    }

    private int m13983e() {
        int i = this.f9120a.miliConfig.weightUnit;
        GuliLog.tracePrintInfo("PersonInfoSettingUnitActivity", "weightUnit: " + this.f9120a.miliConfig.weightUnit);
        return i == 16 ? R.id.person_info_weight_unit_shijin_area : i == 1 ? R.id.person_info_weight_unit_british_area : i == 0 ? R.id.person_info_weight_unit_metric_area : R.id.person_info_weight_unit_metric_area;
    }

    private void m13984f() {
        this.f9124e.setClickable(false);
        this.f9123d.setClickable(false);
        this.f9125f.setClickable(false);
    }

    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.person_info_length_unit_metric_area:
                this.f9120a.miliConfig.unit = 0;
                m13977a(id);
                break;
            case R.id.person_info_length_unit_british_area:
                this.f9120a.miliConfig.unit = 1;
                m13977a(id);
                break;
            case R.id.person_info_weight_unit_metric_area:
                this.f9120a.miliConfig.weightUnit = 0;
                m13979b(id);
                break;
            case R.id.person_info_weight_unit_british_area:
                this.f9120a.miliConfig.weightUnit = 1;
                m13979b(id);
                break;
            case R.id.person_info_weight_unit_shijin_area:
                this.f9120a.miliConfig.weightUnit = 16;
                m13979b(id);
                break;
        }
        GuliLog.tracePrintInfo("PersonInfoSettingUnitActivity", "weightUnit: " + this.f9120a.miliConfig.weightUnit);
        this.f9120a.setNeedSyncServer(2);
        Keeper.keepPersonInfo(this.f9120a);
        EventBus.getDefault().post(new EventPersonInfoUpdateUnit());
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_person_info_setting_unit);
        m13976a();
        GuliLog.tracePrintInfo("PersonInfoSettingUnitActivity", "weightUnit: " + this.f9120a.miliConfig.weightUnit);
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.f3565h);
    }

    public void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.f3565h);
    }
}
